package com.heima.freemarker.controller;

import com.heima.freemarker.entity.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: xsz
 * @DateTime: 2023/12/22 23:49
 **/

@Controller
public class HelloController {

    @GetMapping("/basic")
    public String test(Model model){

        model.addAttribute("name","freemarker");

        Student stu = new Student();
        stu.setName("小明");
        stu.setAge(18);

        model.addAttribute("stu",stu);

        return "01-basic";
    }

    @GetMapping("list")
    public String listTest(Model model){
        //------------------------------------
        Student stu1 = new Student();
        stu1.setName("小强");
        stu1.setAge(18);
        stu1.setMoney(1000.86f);
        stu1.setBirthday(new Date());

        //小红对象模型数据
        Student stu2 = new Student();
        stu2.setName("小红");
        stu2.setMoney(200.1f);
        stu2.setAge(19);

        Map<String,Student> studentMap = new HashMap<>();
        studentMap.put("stu1",stu1);
        studentMap.put("stu2",stu2);
        model.addAttribute("studentMap",studentMap);
        return "02-list";

    }

}
